package com.esisa.dao.hibernate;

import java.util.List;

import org.hibernate.Query;

import com.esisa.dao.MedicamentDao;
import com.esisa.models.Medicament;

public class MedicamentDaoHibernate extends AbstractHibernateDao implements MedicamentDao{

	@Override
	public boolean insert(Medicament medicament) {
		beginTransaction();
		Medicament m=(Medicament) session.get(Medicament.class,medicament.getNom());
		if(m!=null)
			return false;
			session.save(medicament);
		commit();
		return true;
	}

	@Override
	public Medicament select(String id) {
		Medicament medicament;
		 beginTransaction();
		  medicament=(Medicament)session.get(Medicament.class,id);
		 commit();
		return medicament;
	}

	@Override
	public void delete(Medicament medicament) {
		beginTransaction();
			session.delete(medicament);
		commit();
	}
	@Override
	
	public void update(Medicament medicament) {
		beginTransaction();
			session.delete(medicament);
		commit();
	}

	@Override
	public List<Medicament> selectAll() {
		List<Medicament>res=null;
		beginTransaction();
			Query query = session.createQuery("SELECT m FROM Medicament m");
			res=query.list();
		commit();
		return res;
	}
	
	
}
